<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>待办</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="static/js/lay-module/step-lay/step.css" media="all">
    <link rel="stylesheet" href="static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">流程ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="flowid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <jsp:include page="../comm/table.jsp"/>

        <c:if test='${requestScope.taskname == "查勘定损"}'>
            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-sm" lay-event="survey">查勘</a>
            </script>
        </c:if>
        <c:if test='${requestScope.taskname == "核损"}'>
            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-sm" lay-event="verify">核损</a>
            </script>
        </c:if>
    </div>
</div>
<div id="surveyInfo" style="padding: 30px; display: none">
    <jsp:include page="survey.jsp"/>
</div>
<div id="verifyInfo" style="padding: 30px; display: none">
    <jsp:include page="verify.jsp"/>
</div>
<jsp:include page="cartLoss.jsp"/>
<script src="static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="static/js/lay-config.js" charset="utf-8"></script>
<script src="static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="static/js/findUtils.js" charset="utf-8"></script>
<script>
    function showRole(r) {
        return r
    }

    function initUpload(claimmainid) {
        $.getJSON("dataUploadInfo/findUploadInit", "claimmainid=" + claimmainid, function (result) {
            if (result.code == 200) {
                var data = result.data;
                var imgEl;
                $.each(data, function () {
                    var dataurl = this.dataurl;
                    switch (this.dataname) {
                        case "勘察车辆":
                            imgEl = "#img1";
                            break;
                        case "现场方位":
                            imgEl = "#img2";
                            break;
                        case "损失全貌":
                            imgEl = "#img3";
                            break;
                        case "汽车事故面":
                            imgEl = "#img4";
                            break;
                        case "驾驶证":
                            imgEl = "#img5";
                            break;
                        case "行驶证":
                            imgEl = "#img6";
                            break;
                        case "车架号":
                            imgEl = "#img7";
                            break;
                        case "发动机号":
                            imgEl = "#img8";
                            break;
                    }
                    ;
                    $(imgEl).attr('src', 'static/upload/' + dataurl);
                })
            }
        })
    }

    layui.use(['form', 'table', 'laydate', 'upload', 'step'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            upload = layui.upload,
            step = layui.step;

        // 分步表单
        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '基本信息'
            }, {
                title: '文件上传'
            }, {
                title: '定损明细'
            }]
        });

        var formInfo1;
        form.on('submit(formInfo1)', function (data) {
            formInfo1 = data;

            //初始化暂存上传文件
            initUpload(claimmainid);

            //文件上传
            var uploadInst1 = upload.render({
                elem: '#imgBtn1'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "勘察车辆"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText1');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst1.upload();
                    });
                }
            });

            var uploadInst2 = upload.render({
                elem: '#imgBtn2'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "现场方位"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img2').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText2');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst2.upload();
                    });
                }
            });

            var uploadInst3 = upload.render({
                elem: '#imgBtn3'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "损失全貌"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img3').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText3');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst3.upload();
                    });
                }
            });

            var uploadInst4 = upload.render({
                elem: '#imgBtn4'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "汽车事故面"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img4').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText4');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst4.upload();
                    });
                }
            });

            var uploadInst5 = upload.render({
                elem: '#imgBtn5'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "驾驶证"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img5').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText5');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst5.upload();
                    });
                }
            });

            var uploadInst6 = upload.render({
                elem: '#imgBtn6'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "行驶证"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img6').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText6');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst6.upload();
                    });
                }
            });

            var uploadInst7 = upload.render({
                elem: '#imgBtn7'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "车架号"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img7').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText7');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst7.upload();
                    });
                }
            });

            var uploadInst8 = upload.render({
                elem: '#imgBtn8'
                , accept: 'images'
                , acceptMime: 'image/*'
                , url: 'dataUploadInfo/uploadImg' //改成您自己的上传接口
                , data: {"claimmainid": claimmainid, "dataname": "发动机号"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#img8').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == -1) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    return layer.msg('上传成功');
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#imgText8');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst8.upload();
                    });
                }
            });

            step.next('#stepForm');
            return false;
        });

        form.on('submit(formInfo2)', function (data) {
            step.next('#stepForm');
            return false;
        });

        form.on('submit(formStep)', function (data) {
            step.next('#stepForm');
            return false;
        });

        form.on('submit(formStep2)', function (data) {
            step.next('#stepForm');
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });


        // 时间控件
        laydate.render({
            elem: "#dangertime",
            type: 'datetime'
        });
        laydate.render({
            elem: "#casereporttime",
            type: 'datetime'
        });
        laydate.render({
            elem: "#surveylosstime",
            type: 'datetime'
        });

        table.render({
            elem: '#currentTableId',
            url: 'flowinfomation/findFlowDetail/${requestScope.taskname}/${requestScope.jobstate}',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'flowid', title: '流程ID'},
                {field: 'taskname', title: '流程名称'},
                {field: 'assignedname', title: '处理人'},
                {field: 'createtime', title: '创建时间', sort: true},
                {field: 'receivetime', title: '接收时间', sort: true},
                {
                    title: '任务状态', templet: function (d) {
                        return d.transmitstate == 1 ? "正常流转" : d.transmitstate == 2 ? "退回流转" : d.transmitstate == 3 ? "上报流转" : "未知";
                    }
                },
                {
                    field: 'jobstate', title: '任务状态', templet: function (d) {
                        return d.jobstate == 1 ? "待处理" : d.jobstate == 2 ? "接收" : d.jobstate == 3 ? "暂存" : d.jobstate == 4 ? "已处理" : d.jobstate == 5 ? "退回" : "未知状态";
                    }
                },
                {field: 'flowstate', title: '流程状态'},
                {templet: "<div>{{d.claimMainInfo.caseReportInfo.dangercause}}</div>", title: '出险原因'},
                {title: '操作', toolbar: '#currentTableBar'}
            ]],
            page: true,
            limit: 5,
            limits: [5, 10, 15, 20],
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            console.log(data);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        //赔案编号
        var claimmainid;
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            claimmainid = data.claimmainid;

            //如果是待处理状态
            if (data.jobstate == 1) {
                $.get("flowinfomation/updateJobState",
                    "taskid=" + data.taskid + "&jobstate=" + 2,
                    function (result) {
                        if (result.code == 200)
                            layer.msg(result.msg, {icon: 1})
                        else
                            layer.msg(result.msg, {icon: 2})
                    })
            }

            if (obj.event === 'survey') {
                var index = layer.open({
                    title: '查勘报告',
                    type: 1,
                    shade: 0.2,
                    area: ['95%', '95%'],
                    content: $('#surveyInfo'),
                    success: function (layero, index) {
                        table.render({
                            elem: '#caseReport'
                            , data: [{
                                dangertime: layui.util.toDateString(data.claimMainInfo.caseReportInfo.dangertime),
                                dangercause: data.claimMainInfo.caseReportInfo.dangercause,
                                casereporttime: layui.util.toDateString(data.claimMainInfo.caseReportInfo.casereporttime),
                                province: data.claimMainInfo.caseReportInfo.province,
                                city: data.claimMainInfo.caseReportInfo.city,
                                county: data.claimMainInfo.caseReportInfo.county,
                                fulladdress: data.claimMainInfo.caseReportInfo.fulladdress,
                                driver: data.claimMainInfo.caseReportInfo.driver,
                                drivertel: data.claimMainInfo.caseReportInfo.drivertel,
                                dangerpass: data.claimMainInfo.caseReportInfo.dangerpass
                            }]
                            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                            , cols: [[
                                {field: 'dangertime', title: '出险时间'}
                                , {field: 'dangercause', title: '出险原因'}
                                , {field: 'casereporttime', title: '报案时间'}
                                , {
                                    title: '出险地点', templet: function (d) {
                                        return d.province + d.city + d.county + d.fulladdress;
                                    }
                                }
                                , {field: 'dangerpass', title: '出险经过'}
                                , {field: 'driver', title: '出险司机'}
                                , {field: 'drivertel', title: '司机电话'}
                            ]]
                        });
                        var surveyFormData;
                        $.ajax({
                            url: 'surveyLossInfo/findTempInfo',
                            async: false,
                            type: 'get',
                            data: {claimMainId: data.claimmainid},
                            dataType: 'json',
                            success: function (result) {
                                if (result.code == 200) {
                                    surveyFormData = result.data;
                                } else {
                                    surveyFormData = {
                                        taskid: data.taskid,
                                        claimmainid: data.claimMainInfo.claimmainid,
                                        casereportid: data.claimMainInfo.casereportid
                                    }
                                }
                            }
                        });
                        surveyFormData.taskid = data.taskid;
                        surveyFormData.claimmainid = data.claimMainInfo.claimmainid;
                        surveyFormData.casereportid = data.claimMainInfo.casereportid;
                        form.val('surveyForm', surveyFormData);

                        //车损信息
                        findCarLossInfo(table, claimmainid);
                        //物损信息
                        findObjectLossInfo(table, claimmainid);
                        //人伤信息
                        findHumanLossInfo(table, claimmainid);
                    }
                });
                return false;
            } else if (obj.event === 'verify') {
                var index = layer.open({
                    title: '核损信息',
                    type: 1,
                    shade: 0.2,
                    area: ['95%', '95%'],
                    content: $('#verifyInfo'),
                    success: function (layero, index) {
                        // 查询车损信息
                        table.render({
                            elem: '#cartInfoVerify'
                            , url: 'carDamageInfo/findByClaimmainid/' + claimmainid
                            , title: '车损信息表'
                            , cols: [[
                                {field: 'cardamageid', title: '车损信息编号'}
                                , {field: 'claimmainid', title: '赔案编号'}
                                , {field: 'cardamagename', title: '车损部件名称'}
                                , {field: 'lossprice', title: '定损单价'}
                                , {field: 'lossint', title: '损坏数量'}
                                , {field: 'losstotal', title: '定损费用小计'}
                            ]]
                        });

                        // 查询物损信息
                        table.render({
                            elem: '#objectInfoVerify'
                            , url: 'objectDamageInfo/findByClaimmainid/' + claimmainid
                            , title: '物损信息表'
                            , cols: [[
                                {field: 'objectdamage', title: '物损信息编号'}
                                , {field: 'claimmainid', title: '赔案编号'}
                                , {field: 'objectdamagename', title: '物损部件名称'}
                                , {field: 'lossdegree', title: '损失程度'}
                                , {field: 'lossprice', title: '定损单价'}
                                , {field: 'lossint', title: '损坏数量'}
                                , {field: 'losstotal', title: '定损费用小计'}
                            ]]
                        });

                        // 查询人伤信息
                        table.render({
                            elem: '#humanInfoVerify'
                            , url: 'humanInjuryInfo/findByClaimmainid/' + claimmainid
                            , title: '人伤信息表'
                            , cols: [[
                                {field: 'humaninjuryid', title: '人伤详细编号'}
                                , {field: 'claimmainid', title: '赔案编号'}
                                , {field: 'injuredpersonname', title: '伤者姓名'}
                                , {field: 'injurydesc', title: '伤情描述'}
                                , {field: 'costcategory', title: '费用类别'}
                                , {field: 'losstotal', title: '定损费用小计'}
                            ]]
                        });

                        //查询核损总金额
                        $.get("verifyLossInfo/findByClaimMainId", "claimmainid=" + claimmainid, function (result1) {
                            if (result1.code == 200) {
                                $("#sumMoney").text(result1.data.verifylosscost);
                            } else {
                                $.get("verifyLossInfo/computeVerify", "claimmainid=" + claimmainid, function (result) {
                                    if (result.code == 200) {
                                        $("#sumMoney").text(result.data.verifylosscost);
                                    } else {
                                        layer.msg(result.msg, {icon: 2});
                                    }
                                });
                            }
                        });
                        initVerify(form,data);
                    }
                });
                return false;
            }
        });

        //监听暂存
        form.on('submit(tempSave)', function (data) {
            layer.confirm('确定要暂存？', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    url: 'surveyLossInfo/tempSave',
                    type: 'post',
                    data: JSON.stringify(formInfo1.field),
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    success: function (result) {
                        if (result.code == 200) {
                            layer.alert(result.msg, {icon: 1}, function (index) {
                                location.reload();
                            });
                        } else {
                            layer.alert(result.msg, {icon: 2});
                        }
                    }
                });
            });
            return false;
        });

        //提交
        form.on('submit(commitBtn)', function (data) {
            layer.confirm('确定要提交？', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    url: 'surveyLossInfo/commitSurvey',
                    type: 'post',
                    data: JSON.stringify(formInfo1.field),
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    success: function (result) {
                        if (result.code == 200) {
                            layer.alert(result.msg, {icon: 1}, function (index) {
                                location.reload();
                            });
                        } else {
                            layer.alert(result.msg, {icon: 2});
                        }
                    }
                });
            });
            return false;
        });

        //头工具栏事件
        table.on('toolbar(cartInfo)', function (obj) {
            if (obj.event === 'cartLoss') {
                var index = layer.open({
                    title: '车损信息',
                    type: 1,
                    shade: 0.2,
                    area: ['40%', '70%'],
                    content: $('#addCartLoss'),
                });
            } else if (obj.event === 'objectLoss') {
                var index = layer.open({
                    title: '物损信息',
                    type: 1,
                    shade: 0.2,
                    area: ['40%', '70%'],
                    content: $('#addObjectLoss'),
                });
            } else if (obj.event === 'humanLoss') {
                var index = layer.open({
                    title: '人伤信息',
                    type: 1,
                    shade: 0.2,
                    area: ['40%', '70%'],
                    content: $('#addHumanLoss'),
                });
            }
        });

        // 添加车损
        form.on('submit(cartBtn)', function (data) {
            var carInfo = data.field;
            carInfo.claimmainid = claimmainid;
            carInfo.losstotal = carInfo.lossprice * carInfo.lossint;
            $.ajax({
                url: 'carDamageInfo/addCarLoss',
                type: 'post',
                data: JSON.stringify(data.field),
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                success: function (result) {
                    if (result.code == 200) {
                        layer.alert(result.msg, {icon: 1}, function (index) {
                            findCarLossInfo(table, claimmainid);
                            layer.close(index);
                            layer.close(index - 1)
                        })
                    } else {
                        layer.alert(result.msg, {icon: 2}, function (index) {
                            layer.close(index)
                        })
                    }
                }
            });
            return false;
        });

        // 添加物损
        form.on('submit(objectBtn)', function (data) {
            var objInfo = data.field;
            objInfo.claimmainid = claimmainid;
            objInfo.losstotal = objInfo.lossprice * objInfo.lossint;
            $.ajax({
                url: 'objectDamageInfo/addObject',
                type: 'post',
                data: JSON.stringify(data.field),
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                success: function (result) {
                    if (result.code == 200) {
                        layer.alert(result.msg, {icon: 1}, function (index) {
                            findObjectLossInfo(table, claimmainid);
                            layer.close(index);
                            layer.close(index - 1)
                        })
                    } else {
                        layer.alert(result.msg, {icon: 2}, function (index) {
                            layer.close(index)
                        })
                    }
                }
            });
            return false;
        });

        // 添加人伤信息
        form.on('submit(humanBtn)', function (data) {
            var humanInfo = data.field;
            humanInfo.claimmainid = claimmainid;
            $.ajax({
                url: 'humanInjuryInfo/addHuman',
                type: 'post',
                data: JSON.stringify(data.field),
                contentType: 'application/json;charset=utf-8',
                dataType: 'json',
                success: function (result) {
                    if (result.code == 200) {
                        layer.alert(result.msg, {icon: 1}, function (index) {
                            findHumanLossInfo(table, claimmainid);
                            layer.close(index);
                            layer.close(index - 1)
                        })
                    } else {
                        layer.alert(result.msg, {icon: 2}, function (index) {
                            layer.close(index)
                        })
                    }
                }
            });
            return false;
        });

        //删除车损
        table.on('tool(cartInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: 'carDamageInfo/deleteCar?cardamageid=' + data.cardamageid,
                        type: 'get',
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.alert(result.msg, {icon: 1}, function (index) {
                                    obj.del();
                                    layer.close(index);
                                    layer.close(index - 1)
                                })
                            } else {
                                layer.alert(result.msg, {icon: 2}, function (index) {
                                    layer.close(index)
                                })
                            }
                        }
                    })
                });
            }
        });

        //删除物损
        table.on('tool(objectInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: 'objectDamageInfo/deleteObject?objectdamage=' + data.objectdamage,
                        type: 'get',
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.alert(result.msg, {icon: 1}, function (index) {
                                    obj.del();
                                    layer.close(index);
                                    layer.close(index - 1)
                                })
                            } else {
                                layer.alert(result.msg, {icon: 2}, function (index) {
                                    layer.close(index)
                                })
                            }
                        }
                    })
                });
            }
        });

        //删除人伤
        table.on('tool(humanInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: 'humanInjuryInfo/deleteHuman?humaninjuryid=' + data.humaninjuryid,
                        type: 'get',
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.alert(result.msg, {icon: 1}, function (index) {
                                    obj.del();
                                    layer.close(index);
                                    layer.close(index - 1)
                                })
                            } else {
                                layer.alert(result.msg, {icon: 2}, function (index) {
                                    layer.close(index)
                                })
                            }
                        }
                    })
                });
            }
        });
    });
</script>
</body>
</html>